package cm.com.carlamanda.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cm.com.carlamanda.dao.ProjectDAO;
import cm.com.carlamanda.domain.Page;
import cm.com.carlamanda.domain.Project;
import cm.com.carlamanda.service.ProjectService;
import cm.com.carlamanda.util.StringUtil;
@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectDAO projectDao;
   
    @Override
    public List<Project> search(Page page) {
        Map<String,Object> map =new HashMap<String,Object>();
        map.put("startPos", page.getStartPos());
        map.put("endPos", page.getEndPos());
        map.put("sortColumn", page.getSortColumn());
        map.put("sortAsc", page.getSortAsc());
        int count =projectDao.searchProjectCount(map);
        page.setTotalCount(count);
        page.setTotalPage(count);
        return projectDao.search(map);
    }

    @Override
    public Project getProject(Project project) {
        return projectDao.get(project);
    }

    @Override
    public void addProject(Project project) {
        if(StringUtil.isEmpty(project.getId())){
            project.setId(UUID.randomUUID().toString());
        }
        projectDao.insert(project);
    }

    @Override
    public void delProject(Project project) {
        projectDao.del(project);
    }

    @Override
    public void updateProject(Project project) {
        projectDao.update(project);
    }

}
